package com.software.shipperagent.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.software.common.CommonUtils;
import com.software.form.billform.dao.BillForm;
import com.software.form.billform.dao.BillFormTransaction;
import com.software.form.bookingform.dao.BookingFormTransaction;
import com.software.form.cargobooking.dao.CargoBooking;
import com.software.form.cargobooking.dao.CargoBookingTransaction;
import com.software.form.inquiry.sagent.dao.InquirySagentTransaction;
import com.software.form.inquiryform.dao.InquiryForm;
import com.software.form.inquiryform.dao.InquiryFormTransaction;
import com.software.form.interchangeform.dao.InterchangeForm;
import com.software.form.interchangeform.dao.InterchangeFormTransaction;
import com.software.form.packinglist.dao.PackingListTransaction;
import com.software.form.shippingorder.dao.ShippingOrderTransaction;
import com.software.form.shippmentinfo.dao.ShippmentInfo;
import com.software.form.shippmentinfo.dao.ShippmentInfoTransaction;

public class QueryShippmentInfoServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		ShippmentInfoTransaction sit = (ShippmentInfoTransaction)CommonUtils.getBean("shippmentInfoTransaction");
		String email = (String) request.getSession().getAttribute("user");
		List<ShippmentInfo> infos = sit.getShippmentInfos(email);
		List list = new ArrayList();
		if(infos != null){
			for(int i = 0; i < infos.size(); i++){
				JSONArray array = new JSONArray();
				array.put(infos.get(i).getBookingNo());
				array.put(infos.get(i).getInfo());
				list.add(array);
			}
			JSONObject o = new JSONObject();
			try {
				o.put("infos", list);
				CommonUtils.outputJsonData(o.toString(), response);
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
}
